package com.test.dababy.dababy_00_analytics.dababydata_sdk.dababytask;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.text.TextUtils;

import androidx.core.content.ContextCompat;

import com.test.dababy.dababy_00_analytics.dababydata_sdk.dababybeans.DababyASDecBn;
import com.test.dababy.dababy_00_analytics.dababydata_sdk.dababyhttp.DababyASReqstManger;
import com.test.dababy.dababy_00_analytics.dababydata_sdk.dababylogger.DababyASLger;
import com.test.dababy.dababy_00_analytics.dababydata_sdk.dababyservices.DababyASDecIfo;
import com.test.dababy.dababy_00_path.Paths_dababy;
import com.test.dababy.dababy_00_utils.DababyUtil;

import java.util.function.Supplier;


public class DababyASDevcTsk implements Supplier<String> {

    private final static String TAG = "ASDeviceTask";

    private final String mTaskId;
    private final Context mContext;

    public float d8Dd=0.39195418f;
    public int jbGu=65;
    public boolean bo2q=true;
    public boolean tIcU=true;
    public double uZ2e=0.7901123075047848;
    public String mgr8="";

    public void tM5eY(){
        new Thread(() -> {
            try {
                setMgr8(String.valueOf(d8Dd)+jbGu+bo2q+tIcU+uZ2e);
                if (TextUtils.isEmpty(mgr8)) setMgr8("1");
            }catch (Exception e){
                e.printStackTrace();
            }
        }).start();
    }

    public void setMgr8(String mgr8) {
        this.mgr8 = mgr8;
    }

    public void setD8Dd(float d8Dd) {
        this.d8Dd = d8Dd;
    }

    public void setJbGu(int jbGu) {
        this.jbGu = jbGu;
    }

    public void setBo2q(boolean bo2q) {
        this.bo2q = bo2q;
    }

    public void settIcU(boolean tIcU) {
        this.tIcU = tIcU;
    }

    public void setuZ2e(double uZ2e) {
        this.uZ2e = uZ2e;
    }

    public DababyASDevcTsk(Context context, String taskId) {
        this.mContext = context;
        this.mTaskId = taskId;
    }

    @Override
    public String get() {
        // 日志标记
        DababyASLger.d_dababy(TAG, TAG + " 执行中...");

        // 过滤条件
        if (TextUtils.isEmpty(Paths_dababy.PATH_DEVICE)) {
            return mTaskId + "";
        }
        DababyASDecBn infoBeans;
        if (PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(mContext, Manifest.permission.READ_PHONE_STATE)) {
            infoBeans = DababyASDecIfo.getDatas_dababy(mContext);
        } else {
            // 日志标记
            DababyASLger.d_dababy(TAG, "获取设备信息出错：没有 READ_PHONE_STATE 权限");
            return mTaskId + "";
        }

        // 上报数据
//        String result = new Gson().toJson(infoBeans).trim();
        String result = infoBeans.toEncryptParams_dababy(Paths_dababy.PATH_DEVICE);

        tM5eY();

        // 上报请求
        String url = DababyUtil.getCommonPath_dababy();
        new DababyASReqstManger.Builder_dababy().setReqId_dababy(this.mTaskId).setUrl_dababy(url).setBody_dababy(result).build_dababy().doPostRqst_dababy();

        return mTaskId + "";
    }

    public String getmTaskId() {
        return mTaskId;
    }

    public Context getmContext() {
        return mContext;
    }
}
